class Solution(object):
    def numberOfWeakCharacters(self, properties):
        properties.sort(reverse=True)
        ans = 0
        left = 0
        n = len(properties)
        right = 0
        last = - float('inf')
        while right < n:
            if properties[right][0] == properties[left][0]:
                if properties[right][1] < last:
                    ans += 1
                right += 1
            else:
                last = max(properties[left][1], last)
                left = right
        return ans